package com.campus.common.core;

import java.util.ArrayList;
import java.util.List;

public class Utils {

    public static List getPage(List list, Long pageNum, Long pageSize) {
        int totalSize = list.size();
        int fromIndex = (int) ((pageNum - 1) * pageSize);
        int toIndex = (int) Math.min(fromIndex + pageSize, totalSize);

        if (fromIndex > toIndex) {
            // 当起始索引大于结束索引时，返回空列表
            return new ArrayList<>();
        } else {
            // 使用subList方法获取分页数据
            return list.subList(fromIndex, toIndex);
        }
    }
}